<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
        }

        nav {
            position: relative;
            display: flex;
        }

        nav a {
            position: relative;
            margin: 0 20px;
            font-size: 2em;
            color: #000;
            text-decoration: none;
        }

        nav #marker {
            position: absolute;
            left: 0;
            height: 4px;
            width: 0;
            background: #000;
            bottom: -8px;
            transition: .5s;
            border-radius: 4px;
        }
    </style>
</head>

<body>
    <nav>
        <div id="marker"></div>
        <a href="#">Home</a>
        <a href="#">About</a>
        <a href="#">Services</a>
        <a href="#">Portfolio</a>
        <a href="#">Team</a>
        <a href="#">Contact</a>
    </nav>
</body>
<script>
    var marker = document.querySelector('#marker');
    var item = document.querySelectorAll('nav a');

    function indicator(e) {
        marker.style.left = e.offsetLeft + "px";
        marker.style.width = e.offsetWidth + "px";
    }

    item.forEach(link => {
        link.addEventListener('click', (e) => {
            indicator(e.target);
        })
    })
</script>

</html>